home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / logiso.000 / logiso / Utils / RCS / logiso_get.c,v < prev    next >
Encoding:
Text File  |  1995-03-24  |  5.1 KB  |  243 lines

  1. head    1.4;
  2. access;
  3. symbols
  4.     VER_0_3:1.4
  5.     VER_0_2:1.3;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.4
  11. date    95.03.24.11.43.35;    author coulter;    state Exp;
  12. branches;
  13. next    1.3;
  14.  
  15. 1.3
  16. date    95.03.10.02.42.22;    author coulter;    state Exp;
  17. branches;
  18. next    1.2;
  19.  
  20. 1.2
  21. date    95.02.19.16.06.41;    author coulter;    state Exp;
  22. branches;
  23. next    1.1;
  24.  
  25. 1.1
  26. date    95.02.18.08.36.38;    author coulter;    state Exp;
  27. branches;
  28. next    ;
  29.  
  30.  
  31. desc
  32. @get the isofs log
  33. @
  34.  
  35.  
  36. 1.4
  37. log
  38. @Checkin version for 0.3 distribution.
  39. @
  40. text
  41. @
  42. /* logiso_get.c  
  43.    Usage:    logiso_get  [ -v ] cd_mount_point [ log_file ]
  44.       Get the isofs usage log and place it in log_file.  The log is written
  45.       to stdout if log_file is not given.
  46.  
  47.       cd_mount_point can be any valid file path at or below the mount
  48.       point of the cd.
  49.  
  50.       If -v is specified, header information is printed, otherwise just
  51.       a list of inode numbers and operation numbers.
  52. */
  53. /* (C) Copyright 1995 by Michael Coulter.  All rights reserved. */
  54.  
  55. #include <fcntl.h>
  56. #include <linux/iso_fs.h>
  57. #include "/usr/include/linux/iso_fs.h"
  58. #include <stdlib.h>
  59. #include <stdio.h>
  60. #include <sys/types.h>
  61. #include <unistd.h>
  62.  
  63. #define FALSE        0
  64. #define TRUE        1
  65.  
  66. extern void print_usage();
  67. extern void process_args(int argc, 
  68.              char** argv, 
  69.              FILE** out_fp_p, 
  70.              int* verbose_p,
  71.              char** mount_path_p);
  72.  
  73. main(int argc, char** argv)
  74. {
  75.    struct iso_log_entry*    entry_p;
  76.    struct iso_log_entry*    entry_limit_p;
  77.    int                file_id;
  78.    char*            mount_path;
  79.    FILE*            out_fp;
  80.    struct iso_log_info*        iso_log_info_p;
  81.    int                result;
  82.    int                verbose;
  83.  
  84.    process_args(argc, argv, &out_fp, &verbose, &mount_path);
  85.  
  86.    /* file_id = open("/mnt/system_cd/FileList", O_RDONLY); */
  87.    file_id = open(mount_path, O_RDONLY); 
  88.    if (file_id == -1) {
  89.       fprintf(stderr, "Unable to open file %s.\n", mount_path);
  90.       exit(1);
  91.    }
  92.  
  93.    result = ioctl(file_id, ISO_IOC_GETLOGSIZE);
  94.    if (verbose) {
  95.       fprintf(out_fp, "The size is %d, 0x%x\n", result, result);
  96.    }
  97.    if (result < 0) {
  98.       fprintf(stderr, 
  99.                 "Got size %d, aborting.\n", 
  100.                 result);
  101.       exit(1);
  102.    }
  103.    iso_log_info_p = (struct iso_log_info*) malloc(result);
  104.  
  105.    result = ioctl(file_id, ISO_IOC_READLOG, iso_log_info_p);
  106.    if (result != 0) {
  107.       fprintf(stderr, "Failure to read log, status %d\n", result);
  108.       exit(1);
  109.    }
  110.    if (iso_log_info_p->version != ISO_LOG_VERSION) {
  111.       fprintf(stderr, "Expecting version %d, got %d\n", 
  112.               ISO_LOG_VERSION, 
  113.               iso_log_info_p->version);
  114.       /* exit(2); */
  115.    }
  116.    if (verbose) {
  117.       fprintf(out_fp, "version %d\nbuf_format %d\nnsize %d\ndevice %d\n"
  118.                        "overflow_count %d\nnbr_entries %d\n",
  119.           iso_log_info_p->version,
  120.           iso_log_info_p->buf_format,
  121.           iso_log_info_p->size,
  122.           iso_log_info_p->device,
  123.           iso_log_info_p->overflow_count,
  124.           iso_log_info_p->nbr_entries);
  125.    }
  126.  
  127.    entry_p = &iso_log_info_p->log_entry[0];
  128.    entry_limit_p = entry_p + iso_log_info_p->nbr_entries;
  129.    while (entry_p < entry_limit_p) {
  130.       if (entry_p->device == iso_log_info_p->device) {
  131.      fprintf(out_fp, "%ld        %d    %d\n", 
  132.          entry_p->inode, 
  133.          entry_p->operation,
  134.          entry_p->device);
  135.       }
  136.       entry_p++;
  137.    }
  138.    fclose(out_fp);
  139.    return 0;
  140. }
  141.  
  142. void print_usage() 
  143. {
  144.  
  145. char usage_str[] =
  146. "   Usage:    logiso_get  [ -v ] cd_mount_point [ log_file ]\
  147.       Get the isofs usage log and place it in log_file.  The log is written\
  148.       to stdout if log_file is not given.\
  149. \
  150.       cd_mount_point can be any valid file path at or below the mount\
  151.       point of the cd.\
  152. \
  153.       If -v is specified, header information is printed, otherwise just\
  154.       a list of inode numbers and operation numbers.\
  155. ";
  156.    fprintf(stderr, "%s\n", usage_str);
  157. } /* end print_usage */
  158.  
  159. void process_args(int argc, 
  160.           char** argv, 
  161.           FILE** out_fp_p, 
  162.           int* verbose_p, 
  163.           char** mount_path_p)
  164. {
  165.    argc--; argv++;  /* skip command name */
  166.    *verbose_p = FALSE;
  167.    if (argc >= 1 && strcmp(*argv, "-v") == 0) {
  168.       argc--; argv++;  /* done with -v */
  169.       *verbose_p = TRUE;
  170.    }
  171.    if (argc < 1 ) {
  172.       print_usage();
  173.       fprintf(stderr, "No cd_mount_point was provided.\n");
  174.       exit(1);
  175.    }
  176.    *mount_path_p = *argv;  argc--;
  177.    *out_fp_p = stdout;
  178.    if (argc >= 1) {
  179.       if ((*out_fp_p = fopen(*argv, "w") ) == NULL) {
  180.          fprintf(stderr, "Unable to open %s\n", *argv);
  181.      argc--; argv++;  /* done with -v */
  182.       }
  183.    }
  184. } /* end process_args */
  185. @
  186.  
  187.  
  188. 1.3
  189. log
  190. @Checkin files modified to make version 0.2
  191. @
  192. text
  193. @d13 1
  194. @
  195.  
  196.  
  197. 1.2
  198. log
  199. @Checkpoint version 0.1
  200. @
  201. text
  202. @d69 6
  203. d76 2
  204. a77 2
  205.       fprintf(out_fp, "version %d\nbuf_format %d\nnsize %d\noverflow_count %d\n"
  206.                       "nbr_entries %d\n",
  207. d81 1
  208. d89 6
  209. a94 3
  210.       fprintf(out_fp, "%ld        %d\n", 
  211.               entry_p->inode, 
  212.               entry_p->operation);
  213. @
  214.  
  215.  
  216. 1.1
  217. log
  218. @Checkpoint version before fixing /usr/bin install
  219. @
  220. text
  221. @d3 1
  222. a3 1
  223.    Usage:    logiso_get  [ -v ] [ log_file ]
  224. d7 3
  225. d29 2
  226. a30 1
  227.              int* verbose_p);
  228. d37 1
  229. d43 1
  230. a43 1
  231.    process_args(argc, argv, &out_fp, &verbose);
  232. d46 1
  233. a46 1
  234.    file_id = open("/system_cd", O_RDONLY); 
  235. d48 1
  236. a48 1
  237.       fprintf(stderr, "Unable to open file.\n");
  238. d91 22
  239. a112 1
  240. void process_args(int argc, char** argv, FILE** out_fp_p, int* verbose_p)
  241. d120 6
  242. @
  243.